package com.bitcola.security.admin.rest;


import cn.hutool.core.util.ObjectUtil;
import com.bitcola.security.admin.biz.ColaCoinSymbolBiz;
import com.bitcola.security.admin.vo.CoinSymbol;
import com.bitcola.security.common.msg.AppResponse;
import com.bitcola.security.common.rest.BaseController;
import com.bitcola.entity.ColaCoinSymbol;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("cola/symbol")
public class ColaCoinSymbolController extends BaseController<ColaCoinSymbolBiz, ColaCoinSymbol> {

    /**
     * 交易对列表
     * @return
     */
    @RequestMapping("/pages")
    public AppResponse pages(){
        //获取列表
        List<CoinSymbol> list = baseBiz.pages();
        //返回
        return AppResponse.ok().data( list);
    }

    /**
     * 新增
     * @param symbol
     * @return
     */
    @RequestMapping("/modify")
    public AppResponse modify(@RequestBody ColaCoinSymbol symbol){
        //新增
        Boolean bool = baseBiz.modify( symbol);
        if( !bool){
            return AppResponse.error("操作失败");
        }
        return AppResponse.ok();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping("/delete/{id}")
    public AppResponse delete(@PathVariable("id") String id){
        //获取删除的交易对
        CoinSymbol symbol = baseBiz.findByCondition( id);
        if(ObjectUtil.isEmpty( symbol)){
            return AppResponse.error("交易对不存在");
        }
        ColaCoinSymbol newSymbol = new ColaCoinSymbol();
        newSymbol.setId( id);
        newSymbol.setDeleted( 1);
        Boolean bool = baseBiz.deleteSymbol( newSymbol);
        if( !bool){
            return AppResponse.error("删除失败");
        }
        return AppResponse.ok();
    }

    /**
     * 详情
     * @param id
     * @return
     */
    @RequestMapping("/detail/{id}")
    public AppResponse detail(@PathVariable("id") String id){
        //获取详情
        CoinSymbol symbol = baseBiz.findByCondition( id);
        if(ObjectUtil.isEmpty( symbol)){
            return AppResponse.error("交易对不存在");
        }
        return AppResponse.ok().data( symbol);
    }
}